#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <ctype.h>
#include "draw1b.h"


int readInput (FILE * inputFile, Line * Lines, long * inputFileLength) {

    if ( ftell(inputFile) != 0 ) {
        fseek(inputFile, 0L, SEEK_SET);
    }


    int currentLine = 0;
    while ( currentLine < (int) *inputFileLength && !feof(inputFile) ) {
        char * linebuf;
        linebuf = fgets( Lines[currentLine].lineString, MAXLEN, inputFile);
        if (linebuf != NULL) {
        //    printf("%s", linebuf);
            chompim(Lines[currentLine].lineString);
        }

        currentLine++;
    }

    if (currentLine == 0)
        return 0;

    return 1;
}


int processLines (Line * Lines, int inputFileLength) {

    char firstCharInStr;
    for (int currentLine = 0; currentLine < inputFileLength; currentLine++) {
        //printf("Reading: %s", Lines[currentLine].lineString);

        if (!sscanf(Lines[currentLine].lineString, "%c", &firstCharInStr)) {
            return 0;
        }

        decideAction(Lines[currentLine].lineString, firstCharInStr, currentLine);


    }


    return 1;
}


int decideAction (const char * lineString, char firstCharInStr, int currentLine) {

    if (firstCharInStr == '#') {
        //strncpy(myComments[currentLine], lineString, MAXLEN);
    }


    return 1;
}


void chompim (char * lineString) {
    int len = strlen(lineString);
    int offset = 1;

    while ( isspace(lineString[len - offset]) )  {
        offset++;
    }

    lineString[len - offset + 1] = '\0';
}
